
import configparser

class FileInit():

    def __init__(self):
        self.conf_path = '../config/config.ini'
        self.cf = configparser.ConfigParser()
        self.cf.read(self.conf_path)

    def get_conf(self):
        self.secs = self.cf.sections()
        options = self.cf.options(self.secs[0])
        print(options)

        items = self.cf.items(self.secs[0])
        print(items)

        host = self.cf.get(self.secs[0], 'host')
        print(host)

    def set_conf(self, host='localhost', db='test', user='root', pwd='123456'):

        self.cf.set(self.secs[0], 'host', host)
        self.cf.set(self.secs[0], 'db', db)
        self.cf.set(self.secs[0], 'user', user)
        self.cf.set(self.secs[0], 'pwd', pwd)
        self.cf.write(open(self.conf_path, 'w'))


